// driver_side/pages/process/process-map/process-map.js
import { _getPosition } from '../../../utils/Tools'
import { toast } from '../../../../utils/Tools'
const QQMapWX = require('../../../../utils/qqmap-wx-jssdk.min.js');
let qqmap = new QQMapWX({
  key: "D4VBZ-75U6F-7DNJJ-J3TK6-MRVHZ-XFBN4"
})
Page({
  data: {
    id:'',
    address:'',
    poi:{},
    latitude: 23.08331,
    longitude: 113.3172,
  },
  onLoad(options) {
    if(options.id){
      _getPosition().then(res=>{ // 返回定位城市
        console.log(res)
        this.setData({
          id:options.id,
          address: res.result.address,
          latitude:res.result.location.lat,
          longitude:res.result.location.lng,
          // poi: { //根据自己data数据设置相应的地图中心坐标变量名称
          //   latitude: res.result.location.lat,
          //   longitude: res.result.location.lng
          // }
        })
      })
    }
  },
  //      函数事件      // 
  handleSubmit(){ //  点击确认
    wx.redirectTo({
      url:`/driver_side/pages/process/process-finish/process-finish?id=${this.data.id}&address=${this.data.address}`
    });
  },
  handleMapClick(e){  //  点击选择位置
    const {latitude,longitude} = e.detail
    qqmap.reverseGeocoder({
      location: {
        latitude,
        longitude
      },
      success: res=>{
        this.setData({
          address: res.result.address
        })
        toast(res.result.address)
      }
    })
  }
})